package club.banyuan;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

public class NumThread extends Thread {

    private Lock lock;
    private Condition condition;

    public NumThread(Lock lock, Condition condition) {
        this.lock = lock;
        this.condition = condition;
    }
  @Override
  public void run() {
    int num = 1;
    try {
      // 晚一点执行，让打印letter的线程先进入到wait状态
      Thread.sleep(100);
      lock.lock();
      while (num <= 52) {
          System.out.printf("%d %d ", num, num + 1);
          num += 2;
          Thread.sleep(500);
          condition.signal();
          condition.await();
        }
      lock.unlock();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
}
